<template>
  <div class="box">
    <swiper :options="swiperOption">
      <swiper-slide   v-for="(itmes,index) of pages" :key="index">
        <div class="grid"  v-for="itme of itmes" :key="itme.id">
          <div class="icon-image">
            <img class="img" :src="itme.iconUrl" />
          </div>
          <p class="text">{{itme.text}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'icons',
  props: {
    iconLits: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false /* 是否自动滑动 */
      }
    }
  },
  computed: {
    /* 计算分页的计算方法 */
    pages () {
      const pages = []
      this.iconLits.forEach((itme, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(itme)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/config.styl'
  @import '~styles/Mixins.styl'
  /* 设置轮播图的高度，使之空白区域也可以移动 */
  .box >>> .swiper-slide-active
    height: 0
    padding-bottom: 50%
  .box
    margin-top: .2rem
    .grid
      position: relative
      float: left
      width: 25%
      height: 0
      padding-bottom: 25%
      .icon-image
        position: absolute
        top: 0
        left: 0
        right: 0
        bottom: .50rem
        box-sizing: border-box
        padding: .1rem
        .img
          height: 100%
          margin: 0 auto
          display: block
      .text
        position: absolute
        left: 0
        right: 0
        bottom: 0
        height: .50rem
        line-height: .50rem
        text-align: center
        color: $textcorol
        ellipsis()
</style>
